<?php
/*
 *      oswindow.php
 *      
 *      Copyright 2011 ViRak <vetalrakitin@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/oscomponent.php");

class oswindow extends oscomponent {
	
	//public $value;
	//public $readonly = false;
	public $caption;
	public $aligment = "auto";
	
	function __construct($parent) {
		parent::__construct($parent);
		$_SESSION["components"]["windowmanager"]->additem($this->uuid,$this->caption);
	}
	
	function close() {
		if ($this->onclose()) {
			$this->destroy();
			$_SESSION["components"]["windowmanager"]->deleteitem($this->uuid);
		}
	}
	
	//function hide() {}
	//function 
	
	private function style() {
		$ret = get_class($this) == "osmsgbox" ?"z-index:65535;":"z-index:100;";
		if ($this->aligment) {
			switch ($this->aligment) {
				case "center":{
					$this->top = round(($_SESSION["components"]["userinterface"]->height - $this->height)/2);
					$this->left = round(($_SESSION["components"]["userinterface"]->width - $this->width)/2);
					break;
				}	
				case "auto":{break;}
			}
		}
		$ret .= $this->top ? "top:".$this->top."px;":"top:0px;";
		$ret .= $this->left ? "left:".$this->left."px;":"left:0px;";
		$ret .= $this->visible?" visibility:visible;":" visibility:hidden;";
		return "$ret position: absolute;width: auto;height: auto;border-style:solid;border-width:3px;border-color:#85C9FF;background: #ECF1FE;opacity: 1;display: block;";
	}
	
	function get($body) {
		$ret = "<div id='".$this->uuid."' style='".$this->style()."'";
		//$ret .= $this->active?"":" disabled";
		
		$ret .= ">";
		$ret .= "<div style='height: 27px;background: #D1E1FF;' ><table style='width: 100%;border-spacing: 0px;'><tr><td><b>".$this->caption."</b></td><td style='width: 70px;text-align:center;'>";
/*
		if (!$this->minimaze) {$out .= "<input type='button' name='minimaze' value='_' onclick=message('$this->uuid','minimaze','',0);>";} else
		{$out .= "<input type='button' name='minimaze' value='<>' onclick=message('$this->uuid','minimaze','',0);>";}
*/
		$ret .= "<input type='button' name='close' value='X' onclick=message('".$this->uuid."','close',0,0);></td></tr></table></div>";
/*
		if (!$this->minimaze) {$out .= "<div style='opacity: 1;'>".$this->body."</div>";}
*/
		//$ret .= parent::get();
		$ret .= "<div style='opacity: 1;";
		$ret .= $this->height ? "height:".$this->height."px;":"";
		$ret .= $this->width ? "width:".$this->width."px;":"";
		$ret .= "'>".$body."</div>";
		//$ret .= "<pre>".print_r($_SESSION["components"],1)."</pre>";
		$ret .= "</div>";
		return $ret;
		//$ret = "<div id=".$this->uuid;
/*
		$ret = "<div id='".$this->uuid."' style='position: absolute;z-index: 100;top: 0px;left: 0px;width: 100%;height: 100%;background: #FFFFFF;opacity: 0.93;display: block;text-align: center;'>";
*/
/*
		$ret .= $this->active?"":" disabled";
		$ret .= $this->visible?"":" hidden";
		//$ret .= $this->readonly?" readonly":"";
		$ret .= ">";
*/
/*
		$ret .= parent::get();
*/
		//$ret .= $this->value;
		//$ret .= " onkeyup=message(this.id,'onchange',this.value,0)";
/*
		$ret .= "</div>";
*/
/*
		return $ret;
*/
	}
}
?>
